#include <unistd.h>
#include <stdio.h>

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

int main()
{
    //close(1);
    //int fd = open("log.txt",O_WRONLY | O_TRUNC | O_CREAT,0666);
    //printf(" hello world\n"); 
    //fflush(stdout);  为什么只有加了这一句才可以打印到文件中呢?
    //close(fd);
    
    //c语言函数接口
    
    close(1);
    int fd = open("log.txt",O_WRONLY | O_TRUNC | O_CREAT,0666);
    printf(" hello printf\n");
    fprintf(stdout," hello fprintf\n");
    char buffer[] = {" hello write\n"};
    write(1,buffer,strlen(buffer)); 
    fflush(stdout);
    close(fd);
    return 0;
}
